#!/bin/bash
SERVER_NAME=admin
#容器id
CID=$(docker ps -a | grep "$SERVER_NAME" | awk '{print $1}')
#镜像id
IID=$(docker images | grep "$SERVER_NAME" | awk '{print $3}')

if [ -n "$IID" ]; then
		echo "存在$SERVER_NAME容器，CID=$CID,删除容器 ..."
			docker rmi -f $IID
		echo "$SERVER_NAME容器删除完成..."
else
		echo "不存在$SERVER_NAME容器..."
fi

echo "开始构建新镜像"
docker build -t 192.168.207.200/upload/$SERVER_NAME:latest .
docker login 192.168.207.200 -u admin -p Harbor12345
docker push 192.168.207.200/upload/$SERVER_NAME:latest